package game.breeze.socket.util;

import org.apache.mina.core.buffer.IoBuffer;

public class IOBufferWrapper implements BufferWrapper {
	private IoBuffer buffer;

	public IOBufferWrapper() {
		buffer = IoBuffer.allocate(512);
		buffer.setAutoExpand(true);
	}

	@Override
	public void put(byte[] data, int offset, int count) {
		buffer.put(data, offset, count);
	}

	@Override
	public void compact() {
		buffer.compact();
	}

	@Override
	public int remaining() {
		return buffer.remaining();
	}

	@Override
	public void clear() {
		buffer.clear();
	}

	@Override
	public int position() {
		// TODO Auto-generated method stub
		return buffer.position();
	}

	public void position(int newP) {
		buffer.position(newP);
	}

	@Override
	public int readInt() {
		// TODO Auto-generated method stub
		return buffer.getInt();
	}

	@Override
	public byte[] get(int length) {
		byte[] data = new byte[length];
		buffer.get(data);
		return data;
	}

	@Override
	public void writeInt(int value) {
		buffer.putInt(value);
	}

	@Override
	public Object getBuffer() {
		return buffer;
	}

	@Override
	public void reset() {
		// TODO Auto-generated method stub
		buffer.flip();
	}
}
